package com.dzu.easy;

/**
 * @author ZhaoDong
 * @date 2022/10/8 10:25
 * @description 242. 有效的字母异位词
 */
public class Test242 {
    public static void main(String[] args) {
        System.out.println(isAnagram("anagram", "nagaram"));
    }


    public static boolean isAnagram(String s, String t) {
        if (s.length() != t.length()) {
            return false;
        }

        int[] arr = new int[26];

        for (int i = 0; i < s.length(); i++) {
            arr[s.charAt(i) - 'a']++;
            arr[t.charAt(i) - 'a']--;
        }

        for (int i = 0; i < 26; i++) {
            if (arr[i]!=0) {
                return false;
            }
        }

        return true;


    }
}
